package com.yc.demohoudun.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yc.demohoudun.entiy.Product;
import com.yc.demohoudun.entiy.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface UserMapper  extends BaseMapper<User> {
    @Select("SELECT * FROM user")
    List<User> selectAll();

    @Select("select * from user where username=#{username}" +
            " and password=#{password}")
    User selectByUsernameAndPassword(@Param("username") String un,
                                     @Param("password") String ps);


    @Insert("insert into user (username, password,  email) values (#{username},#{password},#{email})")
    void saveUser(User user);

    @Select("SELECT p.name, p.price,p.category,p.detail,p.image\n" +
            "FROM User u\n" +
            "JOIN ownproduct o ON u.username = o.person\n" +
            "JOIN Product p ON o.product = p.name\n" +
            "WHERE u.username =#{username}")
    List<Product> selectByuser(String username);
}
